package com.xike.micromemberserver.service.impl;

import com.xike.micromemberserver.dao.BooksServiceMapper;
import com.xike.micromemberserver.entity.BooksEntity;
import com.xike.micromemberserver.entity.PageInfoMation;
import com.xike.micromemberserver.service.IBooksService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author hongbin
 * @date 2021-04-28 19:10
 * Description：
 */
@Service
public class BooksServiceImpl implements IBooksService {
    @Resource
    private BooksServiceMapper bookServiceMapper;

    @Override
    public List<BooksEntity> selectAll() {
        return bookServiceMapper.selectAll();
    }

    @Override
    public int insert(BooksEntity entity) {
        return bookServiceMapper.insertOne(entity);
    }

    @Override
    public int update(BooksEntity entity) {
        return bookServiceMapper.update(entity);
    }

    @Override
    public int delete(int id) {
        return bookServiceMapper.delete(id);
    }

    @Override
    public int updateChapterTime(int id) {
        return bookServiceMapper.updateChapterTime(id);
    }

    @Override
    public List<BooksEntity> selectByName(PageInfoMation pageInfo) {
        if (pageInfo.getBookName()==null || pageInfo.getBookName().isEmpty()){
            ArrayList<BooksEntity> list = new ArrayList<>();
            list.add(new BooksEntity());
            return list;
        }
        pageInfo.setBookName("%"+pageInfo.getBookName()+"%");
        List<BooksEntity> booksEntities = bookServiceMapper.selectByName(pageInfo.getBookName());
        return booksEntities;
    }

    @Override
    public void approvalBook(BooksEntity booksEntitie) {
        bookServiceMapper.approvalBook(booksEntitie);
    }

    @Override
    public BooksEntity selectById(int id) {
        return bookServiceMapper.selectById(id);
    }

    @Override
    public void addVisits(int id) {
        bookServiceMapper.addVisits(id);
    }

    @Override
    public List<BooksEntity> selectByNameUnApproval(PageInfoMation pageInfo) {
        List<BooksEntity> booksEntities = bookServiceMapper.selectByNameUnApproval(pageInfo);
        return booksEntities;
    }

    @Override
    public List<BooksEntity> selectByType(PageInfoMation pageInfo) {
        if (pageInfo.getBookType()==null || pageInfo.getBookType().isEmpty()){
            ArrayList<BooksEntity> list = new ArrayList<>();
            list.add(new BooksEntity());
            return list;
        }
        pageInfo.setBookName("%"+pageInfo.getBookType()+"%");
        List<BooksEntity> booksEntities = bookServiceMapper.selectByType(pageInfo.getBookType());
        return booksEntities;
    }

    @Override
    public List<BooksEntity> selectByid(int id) {
        return bookServiceMapper.selectByid(id);
    }

    @Override
    public List<BooksEntity> selectUnApproval(PageInfoMation pageInfo) {

        List<BooksEntity> booksEntities = bookServiceMapper.selectUnApproval();
        return booksEntities;
    }

    @Override
    public List<BooksEntity> selectByUploader(PageInfoMation pageInfo) {
        List<BooksEntity> booksEntities = bookServiceMapper.selectByUploader(pageInfo.getUploader());
        return booksEntities;
    }

    @Override
    public List<BooksEntity> selectAlloff() {
        return bookServiceMapper.selectAlloff();
    }

    @Override
    public List<BooksEntity> selectAllByvisits() {
        return bookServiceMapper.selectAllByvisits();
    }

    @Override
    public List<BooksEntity> selectByAny(String keyword) {
        return bookServiceMapper.selectByAny(keyword);
    }
}
